const Constants = require("../../shared/contants");

class Socket {
  constructor(game, io) {
    this.game = game;
    this.io = io;
  }

  listen(socket) {
    //玩家成功连接到socket服务
    console.log(`Player connected!Socket Id: ${socket.id}`); //这里的socket.id是否有问题？

    //加入游戏
    socket.on(
      Constants.MSG_TYPES.JOIN_GAME,
      this.game.joinGame.bind(this.game, socket)
    );

    socket.on(
      Constants.MSG_TYPES.INPUT,
      this.game.handleInput.bind(this.game, socket)
    );
    // 断开游戏
    socket.on("disconnect", this.game.disconnect.bind(this.game, socket));
  }
}

module.exports = Socket;
